package com.haha.community.controller;

import com.haha.community.dao.DiscussPostMapper;
import com.haha.community.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class HelloController {
    @Autowired
    UserMapper userMapper;
    @Autowired
    DiscussPostMapper discussPostMapper;
    @RequestMapping("/hello")
    @ResponseBody
    public String haha(){
        System.out.println(discussPostMapper.selectDiscussPostRows(0));
        //System.out.println(discussPostMapper.selectDiscussPosts(0, 0, 40));
        return "hahaha";
    }
    @RequestMapping("/cook")
    @ResponseBody
    public String hah(HttpServletResponse response, HttpServletRequest request){
        Cookie cookie = new Cookie("cook", "我是一个小饼干");
        HttpSession session = request.getSession();
        //设置生效时间
        cookie.setMaxAge(30*2);
        //设置访问什么路径带上
        cookie.setPath("/community/cook");
        response.addCookie(cookie);
        return "哈哈哈哈";

    }
}
